/**
 * 
 */
package com.estock.web.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.estock.common.model.security.StockCategory;
import com.estock.common.service.impl.BaseServiceImpl;
import com.estock.web.dao.StockCategoryDao;
import com.estock.web.service.StockCategoryService;

/**
 * @author richard
 *
 */
@Service
public class StockCategoryServiceImpl extends BaseServiceImpl implements StockCategoryService {
	
	@Resource
	private StockCategoryDao stockCategoryDao;
	
	public StockCategoryDao getStockCategoryDao() {
		return stockCategoryDao;
	}
	
	@Override
	public StockCategory findStockCategoryByName(String categoryName) {
		return getStockCategoryDao().findStockCategoryByName(categoryName);
	}

	@Override
	public List<StockCategory> findCategoriesByStockId(int stockId) {
		return getStockCategoryDao().findCategoriesByStockId(stockId);
	}
	
	@Override
	public List<StockCategory> findAllActiveStockCategoies() {
		return getStockCategoryDao().findAllActiveStockCategoies();
	}

	@Override
	public void saveOrUpdate(StockCategory stockCategory) {
		getStockCategoryDao().saveOrUpdate(stockCategory);
	}

	@Override
	public void deleteById(Long id) {
		getStockCategoryDao().deleteById(id);
	}

	@Override
	public StockCategory findById(Long id) {
		StockCategory stockCategory = getStockCategoryDao().findById(id);
		// fix LazyInitializationException error
//		for (Stock s: stockCategory.getStocks()) {
//			s.getName();
//		}
		return stockCategory;
	}

	@Override
	public List<StockCategory> findCategoriesByStockCode(String code) {
		return getStockCategoryDao().findCategoriesByStockCode(code);
	}

}
